package com.engineering.elink.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.engineering.elink.common.ErrorType;
import com.engineering.elink.dao.TagMapper;
import com.engineering.elink.domain.Tag;
import com.engineering.elink.service.TagService;
import com.engineering.elink.util.JSONUtil;

@Service
public class TagServiceImpl implements TagService {
	@Autowired
	private TagMapper tagMapper;

	@Override
	public Map<String, Object> add(String tags,String userId) {

		List<Tag> tagList = new ArrayList<Tag>();
		for (String tag : tags.split(",")) {
			Tag t = new Tag();
			t.setName(tag);
			t.setUserId(userId);
			tagList.add(t);
		}
		tagMapper.insertBatch(tagList);
		return JSONUtil.getJSON(ErrorType.SUCCESS,tagMapper.select(tags,userId,tagList.size()));
	}
}
